<?php
namespace Admin\Controller;

class IndexController extends AdminController {
    
    function _initialize() {
        parent::_initialize();
        $this->assign('sys', 'dashboard'); // 数据集
    }
    
    public function index(){
        $oModel = M('order');
        //今日订单数量
        $where['order_state'] = array('EGT',20);
        $where['payment_time'] = array('EGT',strtotime(date('Y-m-d 00:00:30')));
        $todayOrder = $oModel->where($where)->count();
        $this->assign('todayOrder', $todayOrder);
        //今日销售额
        $todayMoney = $oModel->where($where)->sum('order_amount');
        $this->assign('todayMoney', $todayMoney);
        
        //今日发货数量
        $where1['order_state'] = 30;
        $where1['payment_time'] = array('EGT',strtotime(date('Y-m-d 00:00:30')));
        $todaySend = $oModel->where($where1)->count();
        $this->assign('todaySend', $todaySend);
        
        //网站当前浏览量
        $map['time'] = strtotime(date('Y-m-d'));
        $todayVisitor = M('visitor')->where($map)->getField('count');
        $this->assign('todayVisitor', $todayVisitor);
        
        $re = getJson(15,'day','m-d');
        $this->assign('chartArray',$re);
        
        
        $this->assign('action', 'index');
        $this->display();
    }
    
    public function search(){
        layout(FALSE);
        $tp = I('get.tp');
        $keys = I('keys');
        if(!empty($keys)){
            if($tp == 'vrGoods'){
                $keys = I('keys');
                $where['vr_title']=array('like','%'.$keys.'%');
                $where['vr_state'] = 1;
                $count = M('vr_goods')->where($where)->count();
                $Page = new \Think\Page($count, 6); // 实例化分页类 传入总记录数和每页显示的记录数(25)
                $Page->parameter['keys']=$keys;
                $show = $Page->show(); // 分页显示输出
                $arr = M('vr_goods')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->select();
            }else{
                $keys = I('keys');
                $where['goods_title']=array('like','%'.$keys.'%');
                $where['goods_sale'] = 1;
                $where['goods_state'] = 1;
                $count = M('goods')->where($where)->count();
                $Page = new \Think\Page($count, 6); // 实例化分页类 传入总记录数和每页显示的记录数(25)
                $Page->parameter['keys']=$keys;
                $show = $Page->show(); // 分页显示输出
                $arr = M('goods')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->select();
            }
            $this->assign('tp',$tp);
            $this->assign('pages',$show);
            $this->assign('arr', $arr);
        }
        $this->display();
    }
    
    public function searchOn(){
        layout(FALSE);
        $keys = I('keys');
        if (!empty($keys)) {
            $keys = I('keys');
            $where['goods_title'] = array('like', '%' . $keys . '%');
            $where['goods_sale'] = 1;
            $where['goods_state'] = 1;
            $count = M('goods')->where($where)->count();
            $Page = new \Think\Page($count, 6); // 实例化分页类 传入总记录数和每页显示的记录数(25)
            $Page->parameter['keys'] = $keys;
            $show = $Page->show(); // 分页显示输出
            $arr = M('goods')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->select();
            $this->assign('pages', $show);
            $this->assign('arr', $arr);
        }
        $this->display();
    }
    
    public function addGoods(){
        layout(FALSE);
        $keys = I('keys');
        $position_id = I('position_id');
        if (!empty($keys)) {
            $keys = I('keys');
            $where['goods_title'] = array('like', '%' . $keys . '%');
            $where['goods_sale'] = 1;
            $where['goods_state'] = 1;
            $count = M('goods')->where($where)->count();
            $Page = new \Think\Page($count, 6); // 实例化分页类 传入总记录数和每页显示的记录数(25)
            $Page->parameter['keys'] = $keys;
            $show = $Page->show(); // 分页显示输出
            $arr = M('goods')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->select();
            $this->assign('pages', $show);
            $this->assign('arr', $arr);
        }
        $this->assign('position_id', $position_id);
        $this->display();
    }
    
    

}